
CC = g++
LD = g++

OPATH = .generated
BINDIR = bin

# list your binaries here
BINARIES = $(BINDIR)/sumArray 

# don't modify this line
CCFLAGS = -c  
LDFLAGS = -lm -lpthread -lrt 
#LDFLAGS = -lm -lpthread -lrt -lcpc

# add other CFLAGS here
CCFLAGS += 

LINK_MESSAGE = "\033[32;1m\n***Making binary \033[33m%s\033[32m...\n\033[m"
COMPILE_MESSAGE = "\033[32;1m\n*Compiling \033[33m%s\033[32m...\n\033[m"

# list OBJFILES here for each binary
# for files with header dependencies, include build rule below,
# otherwise default build rule is sufficient
OBJFILES_COMMON = $(OPATH)/fatals.o \
				  $(OPATH)/MapReduceScheduler.o
OBJFILES_SUMARRAY = $(OBJFILES_COMMON) \
			        $(OPATH)/main.o

all: $(OPATH) $(BINDIR) $(BINARIES)
	@printf "\033[34;1m\nMy work here is done.\n\033[m"

$(OPATH):
	@printf "\033[32;1m\nMaking \033[33m$(OPATH)/ \033[32mpath for object files...\n\033[m"
	mkdir $(OPATH)

$(BINDIR):
	@printf "\033[32;1m\nMaking \033[33m$(BINDIR)/ \033[32mpath for binaries...\n\033[m"
	mkdir $(BINDIR)

# binary targets are like this
$(BINDIR)/sumArray: $(OBJFILES_SUMARRAY)
	@printf $(LINK_MESSAGE) "sumArray"
	$(LD) $(LDFLAGS) $(OBJFILES_SUMARRAY) -o $@

$(OPATH)/fatals.o: fatals.cpp fatals.h
	@printf $(COMPILE_MESSAGE) "$<"
	$(CC) $(CCFLAGS) $< -o $@

$(OPATH)/main.o: main.cpp fatals.h MapReduceScheduler.h
	@printf $(COMPILE_MESSAGE) "$<"
	$(CC) $(CCFLAGS) $< -o $@

$(OPATH)/MapReduceScheduler.o: MapReduceScheduler.c MapReduceScheduler.h
	@printf $(COMPILE_MESSAGE) "$<"
	gcc $(CCFLAGS) -D_LINUX_ -D_GNU_SOURCE $< -o $@

# default build rule
$(OPATH)/%.o: %.c $(OPATH)
	@printf $(COMPILE_MESSAGE) "$<"
	$(CC) $(CCFLAGS) $< -o $@

almost_clean:
	@printf "\033[34;1m\nMaking \033[31;1malmost\033[34;1m clean ... (saving binaries)\n\033[m"
	-rm -rf core* *.o
	-rm -rf $(OPATH)

clean:
	@printf "\033[34;1m\nCleaning up...\n\033[m"
	-rm -rf core* $(BINARIES) *.o
	-rm -rf $(BINDIR)
	-rm -rf $(OPATH)
	
